package com.sloth.controller;

import com.sloth.pojo.Customer;
import com.sloth.service.ShopCarService;
import com.sloth.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class ShopCarController {
    @Autowired
    private ShopCarService shopCarService;

    @GetMapping("/shopcar")
    @ResponseBody
    public ModelAndView getByCustomerId(Customer customer){

        ServerResponse serverResponse = shopCarService.getByCustomerId(customer.getCustId());
        ModelAndView mav = new ModelAndView();
        mav.addObject("serverResponse",serverResponse);
        mav.setViewName("customer/shopcar");

        return mav;
    }


    @PostMapping("/shopcar/deletesss/{cartId}")
    public String delete(@PathVariable("cartId") Integer cartId ) {
        System.out.println(cartId);
        shopCarService.delete(cartId);

        return "redirect:/shopcar";
    }

}
